package com.yanfan.alarm.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yanfan.alarm.mapper.IbmsAlarmRecordMapper;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.alarm.domain.IbmsAlarmRecord;
import com.yanfan.alarm.service.IIbmsAlarmRecordService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 报警记录Controller
 *
 * @author genluo
 * @date 2024-09-24
 */
@Api(tags = "报警记录")
@RestController
@RequestMapping("/alarm/record")
public class IbmsAlarmRecordController extends BaseController {
    @Autowired
    private IIbmsAlarmRecordService ibmsAlarmRecordService;

    @Autowired
    private IbmsAlarmRecordMapper ibmsAlarmRecordMapper;

    /**
     * 查询报警记录列表
     */
    @ApiOperation("报警记录分页列表")
    @PreAuthorize("@ss.hasPermi('alarm:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsAlarmRecord ibmsAlarmRecord) {
        startPage();
        List<IbmsAlarmRecord> list = ibmsAlarmRecordService.queryPageList(ibmsAlarmRecord);
        return getDataTable(list);
    }

    /**
     * 导出报警记录列表
     */
    @ApiOperation("导出报警记录列表")
    @PreAuthorize("@ss.hasPermi('alarm:record:export')")
    @Log(title = "报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsAlarmRecord ibmsAlarmRecord) {
        List<IbmsAlarmRecord> list = ibmsAlarmRecordService.queryPageList(ibmsAlarmRecord);
        ExcelUtil<IbmsAlarmRecord> util = new ExcelUtil<IbmsAlarmRecord>(IbmsAlarmRecord.class);
        util.exportExcel(response, list, "报警记录数据");
    }

    /**
     * 获取报警记录详细信息
     */
    @ApiOperation("获取报警记录详细信息")
    @PreAuthorize("@ss.hasPermi('alarm:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsAlarmRecordService.getById(id));
    }

    /**
     * 新增报警记录
     */
    @ApiOperation("新增报警记录")
    @PreAuthorize("@ss.hasPermi('alarm:record:add')")
    @Log(title = "报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsAlarmRecord ibmsAlarmRecord) {
        return toAjax(ibmsAlarmRecordService.save(ibmsAlarmRecord));
    }

    /**
     * 修改报警记录
     */
    @ApiOperation("修改报警记录")
    @PreAuthorize("@ss.hasPermi('alarm:record:edit')")
    @Log(title = "报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsAlarmRecord ibmsAlarmRecord) {
        return toAjax(ibmsAlarmRecordService.updateById(ibmsAlarmRecord));
    }

    /**
     * 删除报警记录
     */
    @ApiOperation("删除报警记录")
    @PreAuthorize("@ss.hasPermi('alarm:record:remove')")
    @Log(title = "报警记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsAlarmRecordService.removeBatchByIds(Arrays.asList(ids)));
    }

    @GetMapping("alarmFlow")
    public AjaxResult alarmFlowHour() {

        return AjaxResult.success(ibmsAlarmRecordMapper.alarmFlow());
    }


}
